home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / CD-ROM Tools / CDRPlay / Source / cdrplay.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-27  |  6.8 KB  |  224 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. // CDRPlay.cpp
  3. //
  4. // ©1995,96 SynthoWare
  5. // Simple CD Audio Player that doesn't display track/disk time
  6. //
  7. // Programmed By: Deryk B Robosson
  8. // E-mail:        newlook@free.org
  9. //                nur_hutsko@online.emich.edu
  10. // Snail-mail:    32609 Manistee
  11. //                Westland, MI  48186
  12. //                +1.313.990.3599
  13. // IRC: Channel #amiga as newlook
  14. //
  15. // Used: * AFrame
  16. //         - Amiga C++ OOP Programmers Enhancements
  17. //         - By Jeffry A Worth
  18. //           - e-Mail: worth@online.emich.edu
  19. //                     73410.1112@compuserve.com
  20. //         - And Deryk B Robosson
  21. //           - See above for bug reports etc.
  22. //
  23. //       * CygnusEd Professional v3.6
  24. //         - From CygnusSoft Software
  25. //         - Copyright © 1987-1993 CygnusSoft Software
  26. //
  27. //////////////////////////////////////////////////////////////////////////////
  28.  
  29. //////////////////////////////////////////////////////////////////////////////
  30. // Includes
  31. #include "aframe:cdrplay/cdrplay.hpp"
  32.  
  33. ///////////////////////////////////////////////////////////////////////////////
  34. // About Window Class Definition
  35. // We have to tell the user about us a little bit don't we? ;)
  36.  
  37. class AboutWindow: public AFWindow
  38. {
  39. public:
  40.  
  41.   virtual void OnCreate();
  42.   virtual void OnGadgetUp(LPIntuiMessage imess);
  43.   virtual void OnCloseWindow(LPIntuiMessage imess);
  44.   virtual void DestroyWindow();
  45.  
  46.   AFPanel AboutPanel; // One panel for button
  47.   AFPanel info_panel; // One panel for Info
  48.   AFImageButton AboutButton; // One button!
  49. };
  50.  
  51. //////////////////////////////////////////////////////////////////////////////
  52. // ControlWindow Class Definition
  53. // Main window definitions for our primary input
  54.  
  55. class ControlWindow: public AFWindow
  56. {
  57. public:
  58.   virtual void OnCreate();
  59.   virtual void OnGadgetUp(LPIntuiMessage imess);
  60.   virtual void OnCloseWindow(LPIntuiMessage imess);
  61.   virtual ULONG WindowFlags();
  62.  
  63.   AFCD_Rom cd;
  64.   AFImageButton Next, Prev, Stop, Play, Pause, About; // Our many image buttons
  65. };
  66.  
  67. //////////////////////////////////////////////////////////////////////////////
  68. // ControlWindow Implementation routines
  69.  
  70. // What we do on an exit request from the user
  71.  
  72. void ControlWindow::OnCloseWindow(LPIntuiMessage imess)
  73. {
  74.   AFWindow::DestroyWindow();
  75. }
  76.  
  77. // We override the OnCreate() function so we can do some extra things that it
  78. // doesn't do for us.
  79. void ControlWindow::OnCreate()
  80. {
  81.     cd.CDCreate((UBYTE*)"scsi.device",(ULONG)2);
  82.     cd.SCSI_ReadTOC();
  83.     mytrack=1;
  84. }
  85. // We override the OnGadgetUP function so we can handle the messages accordingly
  86. void ControlWindow::OnGadgetUp(LPIntuiMessage imess)
  87. {
  88.   AFRastPort rp(this);
  89.   AFRect rect, aboutrect;
  90.   AboutWindow *about;
  91.  
  92.   switch(((struct Gadget*)imess->IAddress)->GadgetID) {
  93.   case ID_PLAY:  // User pressed PLAY button
  94.     cd.SCSI_CDPlay((ULONG)2,(ULONG)3); // play from mytrack to end of disc
  95.     printf("Track: %ld\n",mytrack);
  96.     break;
  97.  
  98.   case ID_PAUSE: // User pressed PAUSE Button
  99.     cd.SCSI_CDPause(); // Pause the disc
  100.     break;
  101.  
  102.   case ID_STOP:  // User pressed STOP button
  103.     cd.SCSI_CDStop();  // Stop the disc
  104.     break;
  105.  
  106.   case ID_NEXT:  // User pressed NEXT track button
  107.     mytrack+=1;
  108.     if(mytrack > cd.cd_toc.cdc_NumTracks) // make sure we can advance track
  109.         mytrack=cd.cd_toc.cdc_NumTracks;  // if not, set mytrack to last track
  110.  
  111.     cd.SCSI_CDPlay(mytrack,(ULONG)NULL); // play next track
  112.     printf("Track: %ld\n",mytrack);
  113.     break;
  114.  
  115.   case ID_PREV:  // User Pressed PREV track button
  116.     mytrack-=1;
  117.     if(mytrack==0) // make sure we can decreace track
  118.         mytrack=1; // if not, set mytrack to first track
  119.  
  120.     cd.SCSI_CDPlay(mytrack,(ULONG)NULL); // play previous track
  121.     printf("Track: %ld\n",mytrack);
  122.     break;
  123.  
  124.   case ID_ABOUT:  //User wants to know about us yeah, yeah, yeah!
  125.     aboutrect.SetRect(10,10,212,115);
  126.     about=new AboutWindow;
  127.     about->Create(m_papp,&aboutrect);  // Create our new window and wait...
  128.     break;
  129.  
  130.   default:
  131.     AFWindow::OnGadgetUp(imess);  // the message wasn't for us, return it to Intuition
  132.     break;
  133.   }
  134. }  
  135.  
  136. ULONG ControlWindow::WindowFlags()  // Added WindowFlags
  137. {
  138.   return (AFWindow::WindowFlags() | WFLG_GIMMEZEROZERO);
  139. }
  140.  
  141. //////////////////////////////////////////////////////////////////////////////
  142. // About Window Implementation routines
  143. //
  144. // Deryk Robosson
  145. // December 18,1995
  146. //
  147.  
  148. void AboutWindow::OnCreate() // What we are doing when our AboutWindow
  149. {                            // is being Created
  150.   AFRect rect;
  151.  
  152.   rect.SetRect(2,11,94,103); // Set up our panel because image buttons can't have
  153.                              // Borders on them...
  154.   AboutPanel.Create("",this,&rect,ID_ABOUTPANEL,PANEL_BEVELUP);
  155.  
  156.   rect.SetRect(4,13,92,101); // Set up the main image button
  157.   AboutButton.Create(this,&rect,ID_ABOUTBOX,&about_image,NULL);
  158.  
  159.   rect.SetRect(96,11,184,103); // Create a panel for our useless text to be place in
  160.   info_panel.Create("General Info",this,&rect,ID_ABOUTPANEL,PANEL_BEVELUP);
  161.  
  162.   AFWindow::RefreshGadgets(); // Refresh the glist so we can see what we did! :)
  163. }
  164.  
  165. void AboutWindow::OnGadgetUp(LPIntuiMessage imess)
  166. {
  167.   switch(((struct Gadget*)imess->IAddress)->GadgetID) {
  168.  
  169.   case ID_ABOUTPANEL: // Handle things when user presses any of the three buttons
  170.   case ID_ABOUTBOX:
  171.     AboutWindow::DestroyWindow();
  172.     break;
  173.   default:
  174.     AFWindow::OnGadgetUp(imess); //  Wasn't our message!? :/
  175.     break;
  176.   }
  177. }
  178.  
  179. void AboutWindow::OnCloseWindow(LPIntuiMessage imess) // time to leave!! ;)
  180. {
  181.   AboutWindow::DestroyWindow();
  182. }
  183.  
  184. void AboutWindow::DestroyWindow() // let's get rid of our about window
  185. {
  186.   AFWindow::DestroyWindow();
  187.   delete this;
  188. }
  189.  
  190. //////////////////////////////////////////////////////////////////////////////
  191. // MAIN
  192.  
  193. void main()
  194. {
  195.   AFAmigaApp theApp;
  196.   AFRect rect(10,10,178,60); // Size of our main window
  197.   ControlWindow win;
  198.  
  199.   win.Create(&theApp,&rect,"CDPlay");  // Create our main window
  200.  
  201.   rect.SetRect(2,2,24,35); // Create Previous button
  202.   win.Prev.Create(&win,&rect,ID_PREV,&prev_render_image,&prev_select_image);
  203.  
  204.   rect.SetRect(26,2,48,35); // Create Next button
  205.   win.Next.Create(&win,&rect,ID_NEXT,&next_render_image,&next_select_image);
  206.  
  207.   rect.SetRect(50,2,72,35); // Create Stop button
  208.   win.Stop.Create(&win,&rect,ID_STOP,&stop_render_image,&stop_select_image);
  209.  
  210.   rect.SetRect(74,2,96,35); // Create Play button
  211.   win.Play.Create(&win,&rect,ID_PLAY,&play_render_image,&play_select_image);
  212.  
  213.   rect.SetRect(98,2,120,35); // Create Pause button
  214.   win.Pause.Create(&win,&rect,ID_PAUSE,&pause_render_image,&pause_select_image);
  215.  
  216.   rect.SetRect(122,2,144,35); // Create About button
  217.   win.About.Create(&win,&rect,ID_ABOUT,&about_render_image,&about_select_image);
  218.  
  219.   win.RefreshGadgets(); // Let's refresh so you can see our work!
  220.  
  221.   theApp.RunApp(); // run the app and forget about it, it'll
  222.                    // take care of itself! ;) (isn't C++ wonderful??)
  223. }
  224.